package com.homework.controller;

import com.homework.dto.Result;
import com.homework.entity.DailyHomework;
import com.homework.service.DailyHomeworkService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/daily-homework")
@RequiredArgsConstructor
public class DailyHomeworkController {

    private final DailyHomeworkService dailyHomeworkService;

    /**
     * 获取所有日常作业
     */
    @GetMapping
    public Result<List<DailyHomework>> getAllDailyHomework() {
        return dailyHomeworkService.getAllDailyHomework();
    }

    /**
     * 获取启用的日常作业
     */
    @GetMapping("/active")
    public Result<List<DailyHomework>> getActiveDailyHomework() {
        return dailyHomeworkService.getActiveDailyHomework();
    }

    /**
     * 创建日常作业
     */
    @PostMapping
    public Result<String> createDailyHomework(@RequestBody DailyHomework dailyHomework) {
        return dailyHomeworkService.createDailyHomework(dailyHomework);
    }

    /**
     * 更新日常作业
     */
    @PutMapping("/{id}")
    public Result<String> updateDailyHomework(@PathVariable Long id, @RequestBody DailyHomework dailyHomework) {
        dailyHomework.setId(id);
        return dailyHomeworkService.updateDailyHomework(dailyHomework);
    }

    /**
     * 删除日常作业
     */
    @DeleteMapping("/{id}")
    public Result<String> deleteDailyHomework(@PathVariable Long id) {
        return dailyHomeworkService.deleteDailyHomework(id);
    }

    /**
     * 启用/禁用日常作业
     */
    @PutMapping("/{id}/toggle")
    public Result<String> toggleDailyHomework(@PathVariable Long id, @RequestParam Boolean isActive) {
        return dailyHomeworkService.toggleDailyHomework(id, isActive);
    }

    /**
     * 调整日常作业排序
     */
    @PutMapping("/reorder")
    public Result<String> reorderDailyHomework(@RequestBody List<Long> ids) {
        return dailyHomeworkService.reorderDailyHomework(ids);
    }
}